package com.hframe.typefilter;

import org.apache.log4j.Logger;
import sun.misc.BASE64Encoder;

/**
 * Base64加密
 * 
 * @author Administrator
 *
 */
public class Base64Encoder implements FilterRef<Object, String> {
	static Logger log = Logger.getLogger(Base64Encoder.class);

	@Override
	public Object filter( String object) {
		return encoder(object);
	}

	public static String encoder(String object) {
		if (object != null && object.length() > 0) {
			BASE64Encoder encoder = new BASE64Encoder();
			try {
				return encoder.encode(object.getBytes("utf-8"));
			} catch (Exception e) {
				log.error(e, e);
			}
		}
		return "";
	}

	public static String encoder(byte[] object) {
		if (object != null && object.length > 0) {
			BASE64Encoder encoder = new BASE64Encoder();
			try {
				return encoder.encode(object);
			} catch (Exception e) {
				log.error(e, e);
			}
		}
		return "";
	}

}